﻿#include "FITKAcousticsAbsPhysicsProp.h"
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
#include "FITKAcousticsAbsMaterial.h"
#include "FITKAcousticsAbsPhysicsProp.h"

namespace Acoustics
{
    FITKAcousticsAbsPhysicsProp::~FITKAcousticsAbsPhysicsProp()
    {
    }


    Acoustics::FITKAcousticsAbsPhysicsProp::AcousticsPhyscisPropType FITKAcousticsAbsPhysicsProp::getPhysicsPropType()
    {
        //基类错误值
        return AcousticsPhyscisPropType::APPNone;
    }

    void FITKAcousticsAbsPhysicsProp::setMaterialID(const int id)
    {
        _materialID = id;
    }

    int FITKAcousticsAbsPhysicsProp::getMaterialID() const
    {
        return _materialID;
    }

    QString FITKAcousticsAbsPhysicsProp::getMaterialName()
    {
        //错误判断
        if (_materialID <= 0) return "";
        //获取对象
        FITKAcousticsAbsMaterial* mat = this->getMaterial();
        return mat == nullptr ? "" : mat->getDataObjectName();
    }

    Acoustics::FITKAcousticsAbsMaterial* FITKAcousticsAbsPhysicsProp::getMaterial()
    {
        //从数据仓库获取
        return FITKDATAREPO->getTDataByID<Acoustics::FITKAcousticsAbsMaterial>(_materialID);
    }


    void FITKAcousticsAbsPhysicsProp::setDescribe(const QString& des)
    {
        _describe = des;
    }

    QString FITKAcousticsAbsPhysicsProp::getDescribe()
    {
        return _describe;
    }

    void FITKAcousticsAbsPhysicsProp::setColor(float r, float g, float b)
    {
        _color[0] = r;
        _color[1] = g;
        _color[2] = b;
    }

    void FITKAcousticsAbsPhysicsProp::getColor(float* rgb)
    {
        if (rgb == nullptr || _color == nullptr) return;

        for (int i = 0; i < 3; i++)
            rgb[i] = _color[i];
    }

    void FITKAcousticsAbsPhysicsProp::updateDefaultColor()
    {
    }

    QList<FITKAcousticsAbsPhysicsProp*> FITKAcousticsPhysicsPropManager::getPhysicsProps(FITKAcousticsAbsPhysicsProp::AcousticsPhyscisPropType t)
    {
        //存储符合类型的成员
        QList<FITKAcousticsAbsPhysicsProp*> pls;
        const int n = this->getDataCount();
        //遍历全部对象
        for (int i = 0; i < n; ++i)
        {
            FITKAcousticsAbsPhysicsProp* p = this->getDataByIndex(i);
            if (p == nullptr) continue;
            //类型筛选
            if (p->getPhysicsPropType() == t)
                pls.append(p);
        }
        return pls;
    }

}


